#ifndef DIRECTORYMANAGER_HPP
#define	DIRECTORYMANAGER_HPP

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>

#include "utils.hpp"
#include "buffermanager.hpp"

using namespace std;

class directoryManager
{
	public:
		directoryManager(char* disk);
		~directoryManager();

		// Estructura dels registres
		struct slot {
		    string fileName;
            unsigned short firstPag;
            int tipus;
            int mr;
            int mcc;
		    unsigned short slotNum;
		};
		
		bufferManager* _buffman;
		char* _pagCtrl;
		
        // -------------------------------------------------------------------------------
        // Funcions que gestionen les pagines del disc
        // -------------------------------------------------------------------------------
        int getFreePag();
        void setFreePag(const int &n);
        void setUsedPag(const int &n);
        bool isPagInUse(const int &n);
        
        void setNextPagVal(const int &currPag, const unsigned short &nextPag);
        unsigned short getNextPagVal(const int &pag);
		
		slot getSlot(const int &n);
		slot getSlot(const string &fileName);
		void setSlot(const slot &s);
        void updateSlot(const slot &s);
		bool validSlot(const int &n);
		
        // -------------------------------------------------------------------------------
        // Funcions que gestionen els fitxers del disc
        // -------------------------------------------------------------------------------
		void newControl();
        unsigned short getFreeSlot();
        void setFreeSlot(const int &n);
        void deleteSlot(const int &n);
        
        unsigned short readUShort(const int &pos1, const int &pos2);
        void writeUShort(const unsigned short &valor, const int &pos1, const int &pos2);
        
	private:
        
};

#endif
